package com.ctshk.task.worker.processors;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ctshk.common.dto.Result;
import com.ctshk.rpc.order.goods.service.IOrderTaskService;
import com.github.kfcfans.powerjob.worker.core.processor.ProcessResult;
import com.github.kfcfans.powerjob.worker.core.processor.TaskContext;
import com.github.kfcfans.powerjob.worker.core.processor.sdk.BasicProcessor;
import com.github.kfcfans.powerjob.worker.log.OmsLogger;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

/**
 * TODO
 * 中旅到家商品订单付款超时 - 单机处理器
 * @author 黄利斌
 * @date 2021/5/21 3:09 下午
 */
@Slf4j
@Component
public class OrderCommodityExpiresProcessor implements BasicProcessor {

    @DubboReference
    private IOrderTaskService iOrderTaskService;

    @Override
    public ProcessResult process(TaskContext taskContext) throws Exception {
        OmsLogger omsLogger = taskContext.getOmsLogger();
        JSONObject jsonObject = JSON.parseObject(taskContext.getInstanceParams());
        Long orderId = jsonObject.getLong("id");
        Result result = iOrderTaskService.notPaid(orderId);
        if (!result.isSuccess()){
            omsLogger.error("订单设置未付款状态失败");
        }else {
            omsLogger.info("订单设置未付款状态成功");
        }
        // 根据控制台参数判断是否成功
        boolean success = !"failed".equals(taskContext.getJobParams());
        omsLogger.info("OrderAirExpressExpiresProcessor finished process,success: .", success);

        return new ProcessResult(success, taskContext + ": " + success);
    }
}
